﻿Imports Microsoft.DirectX.Direct3D
Imports Microsoft.DirectX
Public Class AnimationVulkanEinschlag
    Inherits ObjektAnimation
    Const HalteFrame As Integer = 2
    Dim Zaehler As Integer = 0
    Public Sub New(ByVal X As Integer, ByVal Y As Integer, ByVal Musikspielen As Boolean)
        MyBase.New(True, ObjektSpielfeld.Bodenschlacht)
        P.X = X
        P.Y = Y
        Frames = 1
        BildID = LoadTextur("VulkanEinschlag", Frames - 1)
        If DataSettings.MusikSound Then
            '    MusikEngine.LoadWav(DataSettings.Resourcenpfad + "Sound\Sound Effects\Overworld\Explosion+Bombe.wav", False)
        End If
    End Sub

    Public Overrides Function Malen(ByVal intColor As System.Drawing.Color, Optional ByVal Zoomfaktor As Single = 1.0, Optional ByVal Feldbreite As Integer = -1) As Boolean
        If DataSettings.draw3D Then

        ElseIf DataSettings._2D_3D_Malen Then
            Dim T As Textur = Texturen(BildID)
            Dim Pos As Point
            If Frame < 5 Then
                Pos = New Drawing.Point(P.X, P.Y - 10 * (4 - Frames) / Hauptmenue.Feldbreite)
            Else
                Pos = New Drawing.Point(P.X, P.Y)
            End If
            SetFrameBild(Frame)

            Dim MittelPunkt As Point = Grafikengine.ptfRotCenter
            Dim Bildgroesse As Size = Grafikengine.recBild.Size

            Dim XPlus As Single = -MittelPunkt.X / Hauptmenue.Feldbreite
            Dim YPlus As Single = -(Bildgroesse.Height - MittelPunkt.Y) / Hauptmenue.Feldbreite

            Dim Rechts As Single = (Bildgroesse.Width) / Hauptmenue.Feldbreite
            Dim Oben As Single = (Bildgroesse.Height) / Hauptmenue.Feldbreite

            Dim GesamtGroesse As Integer = T.EinzelbildGroesse.Width * (Frames)


            Dim cube(3) As CustomVertex.PositionTextured
            cube(0) = New CustomVertex.PositionTextured(0, 0, 0, Grafikengine.recBild.X / GesamtGroesse, 1)
            cube(1) = New CustomVertex.PositionTextured(0, 0, Oben * Zoomfaktor, Grafikengine.recBild.X / GesamtGroesse, 0)
            cube(2) = New CustomVertex.PositionTextured(Rechts * Zoomfaktor, 0, 0, Grafikengine.recBild.X / GesamtGroesse + Grafikengine.recBild.Width / GesamtGroesse, 1)
            cube(3) = New CustomVertex.PositionTextured(Rechts * Zoomfaktor, 0, Oben * Zoomfaktor, Grafikengine.recBild.X / GesamtGroesse + Grafikengine.recBild.Width / GesamtGroesse, 0)
            Dim Vec As Vector3
            Vec = ObjektSpielfeld.CalcDraw2D3DVec(CSng(Pos.X) + XPlus + 0.5, ObjektSpielfeld.SpielfeldLayer.Animationen, CSng(Pos.Y) - YPlus - 0.5)
            Grafikengine.malen2Din3D(Vec, cube, T.TexturBild, intColor)

        Else
            Dim sngRotation As Double = 0
            Dim T As Textur = Texturen(BildID)
            Grafikengine.szfScale = Nothing
            If Frame < 5 Then
                Grafikengine.ptfPosition = New Drawing.Point(Hauptmenue.Feldbreite * P.X + Objektverwalter.Spielfeld.BildschirmKooX, Hauptmenue.Feldbreite * P.Y + Objektverwalter.Spielfeld.BildschirmKooY - 10 * (4 - Frames))
            Else
                Grafikengine.ptfPosition = New Drawing.Point(Hauptmenue.Feldbreite * P.X + Objektverwalter.Spielfeld.BildschirmKooX, Hauptmenue.Feldbreite * P.Y + Objektverwalter.Spielfeld.BildschirmKooY)
            End If
            SetFrameBild(Frame)
            Grafikengine.Sprite.Draw2D(T.TexturBild, Grafikengine.recBild, Grafikengine.szfScale, Grafikengine.ptfRotCenter, sngRotation, Grafikengine.ptfPosition, intColor)
        End If
        Frame += 1
        If Frame < 9 Then
            Return True
        Else
            Return False
        End If
    End Function

    Public Sub SetFrameBild(ByVal Frame As Integer)
        Select Case Frame
            Case Is < 5
                If Hauptmenue.ZoomedIn Then
                    With Grafikengine.recBild
                        .X = 0 : .Width = 21
                        .Y = 0 : .Height = Hauptmenue.Feldbreite * 5 / 2
                    End With
                    Grafikengine.ptfRotCenter = New Point(10, Hauptmenue.Feldbreite * 5 / 4)
                Else
                    With Grafikengine.recBild
                        .X = 0 : .Width = 14
                        .Y = 0 : .Height = Hauptmenue.Feldbreite * 5 / 2
                    End With
                    Grafikengine.ptfRotCenter = New Point(7, Hauptmenue.Feldbreite * 5 / 4)
                End If

            Case Is < 7
                If Hauptmenue.ZoomedIn Then
                    With Grafikengine.recBild
                        .X = 21 : .Width = 32
                        .Y = 0 : .Height = Hauptmenue.Feldbreite * 5 / 2
                    End With
                    Grafikengine.ptfRotCenter = New Point(16, Hauptmenue.Feldbreite * 5 / 4)
                Else
                    With Grafikengine.recBild
                        .X = 14 : .Width = 21
                        .Y = 0 : .Height = Hauptmenue.Feldbreite * 5 / 2
                    End With
                    Grafikengine.ptfRotCenter = New Point(10, Hauptmenue.Feldbreite * 5 / 4)
                End If
            Case Is < 9
                If Hauptmenue.ZoomedIn Then
                    With Grafikengine.recBild
                        .X = 53 : .Width = 42
                        .Y = 0 : .Height = Hauptmenue.Feldbreite * 5 / 2
                    End With
                    Grafikengine.ptfRotCenter = New Point(21, Hauptmenue.Feldbreite * 5 / 4)
                Else
                    With Grafikengine.recBild
                        .X = 35 : .Width = 28
                        .Y = 0 : .Height = Hauptmenue.Feldbreite * 5 / 2
                    End With
                    Grafikengine.ptfRotCenter = New Point(14, Hauptmenue.Feldbreite * 5 / 4)
                End If
            Case Is < 11
                If Hauptmenue.ZoomedIn Then
                    With Grafikengine.recBild
                        .X = 95 : .Width = Hauptmenue.Feldbreite * 2
                        .Y = 0 : .Height = Hauptmenue.Feldbreite * 5 / 2
                    End With
                    Grafikengine.ptfRotCenter = New Point(Hauptmenue.Feldbreite / 2, Hauptmenue.Feldbreite * 5 / 4)
                Else
                    With Grafikengine.recBild
                        .X = 63 : .Width = Hauptmenue.Feldbreite * 2
                        .Y = 0 : .Height = Hauptmenue.Feldbreite * 5 / 2
                    End With
                    Grafikengine.ptfRotCenter = New Point(Hauptmenue.Feldbreite / 2, Hauptmenue.Feldbreite * 5 / 4)
                End If
        End Select
    End Sub
End Class
